//*************************************************************************//
//*           _____   ____________            ______               __     *//
//*          / /__ \ / ____/ ____/           / ____/___  _________/ /     *//
//*     __  / /__/ // __/ / __/    ______   / /_  / __ \/ ___/ __  /      *//
//*    / /_/ // __// /___/ /___   /_____/  / __/ / /_/ / /  / /_/ /       *//
//*    \____//____/_____/_____/           /_/    \____/_/   \__,_/        *//
//*                                                                       *//
//*     Copyright (c) 2006 Ford Argentina. All Rights Reserved.           *//
//*                                                                       *//
//*************************************************************************//

package ar.com.ford.it.webengine.system.logs;

import java.io.File;
import ar.com.ford.it.webengine.compressor.FileCompressor;
import ar.com.ford.it.webengine.settings.AppSettings;
import com.ford.it.logging.ILogger;
import com.ford.it.logging.LogFactory;

/**
 * LogsCompressor <br>
 * 
 * Comprime los logs de la aplicacion en un archivo zip
 * 
 * @author Aji
 */
public class LogsCompressor {

	private static final String CLASS_NAME = LogsCompressor.class.getName();
	private static final ILogger log = LogFactory.getInstance().getLogger(CLASS_NAME);


	/**
	 * Obtener array de bytes conteniendo un archivo zip con los logs de la aplicacion.
	 * 
	 * @return array de bytes conteniendo un archivo zip con los logs de la aplicacion.
	 */
	public byte[] getZippedLogs() {
		String METHOD_NAME = "getZippedLogs";
		
		log.entering(CLASS_NAME, METHOD_NAME);
		
		String inFileNames="";
		String directory = AppSettings.getInstance().getAPP_PATH();
		directory += File.separator+"logs";
		
		File dir = new File(directory);
		File[] files = dir.listFiles();
		
		
		
		for (int i=0; i < files.length; i++) {
			inFileNames += files[i].getAbsolutePath()+",";	
		}
		
		byte[] result = FileCompressor.CompressFiles(inFileNames);
		
		log.exiting(CLASS_NAME, METHOD_NAME);
		return result;
	}

}
